package com.test01_程序基础;

/**
 * 方法
 */
public class YootkDemo_06 {

    public static void main(String[] args) {
        printMessage();
        System.out.printf("sum(%d, %d) = %d%n", 10, 20, sum(10, 20));
        System.out.printf("sum(%d) = %d%n", 10, sum(10));
    }

    public static void printMessage() {
        System.out.println("*******************************");
        System.out.println("****     www.yootk.com    *****");
        System.out.println("*******************************");
    }

    public static int sum(int... nums) {
        int result = 0;
        for (int num : nums) {
            result += num;
        }
        return result;
    }

    public static int sum(int num) {
        if (num <= 0) {
            return 0;
        }
        return num + sum(num - 1);  // 递归调用
    }
}
